<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', 'LoginController@welcome');


//用户模块
//注册页面
Route::get('/register', 'RegisterController@index');
//注册行为
Route::post('/register', 'RegisterController@register');
//登录页面
Route::get('/login', 'LoginController@index');
//登录行为
Route::post('/login', 'LoginController@login');


Route::group(['middleware' => 'auth:web'], function () {
    //登出行为
    Route::get('/logout', 'LoginController@logout');
    //个人设置页面
    Route::get('/user/me/setting', 'UserController@setting');
    //个人设置行为
    Route::post('/user/me/setting', 'UserController@settingStore');


    //文章列表页
    Route::get('/posts', 'PostController@index');
    //文章详情页 -- 模型绑定
    Route::get('/posts/{post}', 'PostController@show')->where('post', '[0-9]+');
    //创建文章
    Route::get('/posts/create', 'PostController@create');
    Route::post('/posts', 'PostController@store');
    //编辑文章  -- 模型绑定
    Route::get('/posts/{post}/edit', 'PostController@edit');
    Route::put('/posts/{post}', 'PostController@update');
    //删除文章
    Route::get('/posts/{post}/delete', 'PostController@delete');
    //图片上传
    Route::post('/posts/image/upload', 'PostController@imageUpload');
    //提交评论
    Route::post('/posts/{post}/comment', 'PostController@comment');

    //赞
    Route::get('/posts/{post}/zan', 'PostController@zan');
    //取消赞
    Route::get('/posts/{post}/unzan', 'PostController@unzan');
    //搜索
    Route::get('/posts/search', 'PostController@search');

    //个人中心
    Route::get('/user/{user}', 'UserController@show');
    Route::post('/user/{user}/fan', 'UserController@fan');
    Route::post('/user/{user}/unfan', 'UserController@unfan');

    //专题详情页
    Route::get('/topic/{topic}', 'TopicController@show');
    //投稿
    Route::post('/topic/{topic}/submit', 'TopicController@submit');

    //通知
    Route::get('/notices', 'NoticeController@index');
});


//引入后台管理路由文件
//include_once('admin.php');


//管理后台
Route::group(['prefix' => 'admin'], function () {

    //登录展示页
    Route::get('/login', '\App\Admin\Controllers\LoginController@index');
    //登录行为
    Route::post('/login', '\App\Admin\Controllers\LoginController@login');
    //登出行为
    Route::get('/logout', '\App\Admin\Controllers\LoginController@logout');

    Route::group(['middleware' => 'auth:admin'], function () {
        //首页
        Route::get('/home', '\App\Admin\Controllers\HomeController@index');

        Route::group(['middleware' => 'can:system'], function () {
            //管理人员模块
            Route::get('/users', '\App\Admin\Controllers\UserController@index');
            Route::get('/users/create', '\App\Admin\Controllers\UserController@create');
            Route::post('/users/store', '\App\Admin\Controllers\UserController@store');
            Route::get('/users/{user}/role', '\App\Admin\Controllers\UserController@role');
            Route::post('/users/{user}/role', '\App\Admin\Controllers\UserController@storeRole');
            //角色
            Route::get('/roles', '\App\Admin\Controllers\RoleController@index');
            Route::get('/roles/create', '\App\Admin\Controllers\RoleController@create');
            Route::post('/roles/store', '\App\Admin\Controllers\RoleController@store');
            Route::get('/roles/{role}/permission', '\App\Admin\Controllers\RoleController@permission');
            Route::post('/roles/{role}/permission', '\App\Admin\Controllers\RoleController@storePermission');
            //权限
            Route::get('/permissions', '\App\Admin\Controllers\PermissionController@index');
            Route::get('/permissions/create', '\App\Admin\Controllers\PermissionController@create');
            Route::post('/permissions/store', '\App\Admin\Controllers\PermissionController@store');
        });

        Route::group(['middleware' => 'can:post'], function () {
            //文章审核模块
            Route::get('/posts', '\App\Admin\Controllers\PostController@index');
            Route::post('/posts/{post}/status', '\App\Admin\Controllers\PostController@status');
        });

        //专题
        Route::group(['middleware' => 'can:topic'], function () {
            Route::resource('/topics', '\App\Admin\Controllers\TopicController', ['only' => ['index', 'create', 'store', 'destroy']]);
        });

        //通知
        Route::group(['middleware' => 'can:notice'], function () {
            Route::resource('/notices', '\App\Admin\Controllers\NoticeController', ['only' => ['index', 'create', 'store']]);
        });


    });

});


